package lib.ui{
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	public class Button extends Sprite{
		
		private var filter : Array = [new GlowFilter(0xFFE600, 1, 8, 8, 9)];
		private var filterClick : Array = [new GlowFilter(0xFF0000, 1, 8, 8, 9)];
		
		private var _flag:uint = 0;
		
		public function Button(text:String){
			this.mouseChildren = false;
			var squareSize:uint = 100;
			var square:Shape = new Shape();
			square.graphics.beginFill(0xFF0000, 0.5);
			square.graphics.drawRoundRect(0,0,60,30,10,10);
			square.graphics.endFill();
			this.addChild(square);
			
			var textField:TextField = new TextField();
			textField.defaultTextFormat = new TextFormat("Times New Roman",12,0xFFFFFF,true);
			textField.y = 5;
			textField.width = 60;
			textField.height = 30;
			textField.text = text;
			textField.autoSize = TextFieldAutoSize.CENTER;
			this.addChild(textField);
			
			this.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
			this.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
			this.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
			this.addEventListener(MouseEvent.MOUSE_UP, onRollOver);
		}
		
		public function setFlag(flag:uint):void{
			_flag = flag;
		}
		
		public function getFlag():uint{
			return _flag;
		}
		
		private function onRollOver(e:MouseEvent):void {
			this.filters = filter;
		}
		
		private function onRollOut(e:MouseEvent):void {
			this.filters = [];
		}
		
		private function onClick(e:MouseEvent):void{
			this.filters = filterClick;
		}
	}
}